package com.zany.ibatis.dialect;



/**
 * 分页 目前系统未使用该方法
 * @author chengY
 * @version 1.0
 */
public class OracleDialect implements Dialect {
	protected static final String SQL_END_DELIMITER = ";";

	public String getLimitString(String sql, boolean hasOffset) {
		return sql;
	}

	public String getLimitString(String sql, int offset, int limit) {
		sql = trim(sql);
		StringBuffer sb = new StringBuffer(sql.length() + 100);
		sb.append("select * from (select t.*, rownum rn from (");
		sb.append(sql);
		sb.append(")t where rownum<=  ");
		sb.append(offset+limit);
		sb.append(" ) where  rn >");
		sb.append(offset);
		
		return sb.toString();
	}

	public boolean supportsLimit() {
		return true;
	}

	private String trim(String sql) {
		sql = sql.trim();
		if (sql.endsWith(SQL_END_DELIMITER)) {
			sql = sql.substring(0, sql.length() - 1
					- SQL_END_DELIMITER.length());
		}
		return sql;
	}

}
